﻿using System;
using System.Drawing;
using System.Windows.Forms;

namespace Pitaya_IDE
{
    public class FileOperation
    {
        public delegate void FileBackcall();
        FileBackcall[] backcall = new FileBackcall[4];

        Form1 form1;
        Panel panel, ColorPanel;
        Label[] Labelbtu = new Label[4];

        public FileOperation(Form1 _form1, Panel _panel, Panel _ColorPanel,
            FileBackcall _newFile, 
            FileBackcall _newFolder,
            FileBackcall _Refresh, 
            FileBackcall _foldFolder
            )
        {
            form1 = _form1;
            panel = _panel;
            ColorPanel = _ColorPanel;

            backcall[0] = _newFile;
            backcall[1] = _newFolder;
            backcall[2] = _Refresh;
            backcall[3] = _foldFolder;

            Labelbtu[0] = new Label()
            {
                Name = "LabelnewFile",
                Location = new Point(0,0),
                Size = new Size(38,38),
                BackColor = ColorPanel.BackColor,
            };

            Labelbtu[1] = new Label()
            {
                Name = "LabelnewFolder",
                Location = new Point(45, 0),
                Size = new Size(38, 38),
                BackColor = ColorPanel.BackColor,
            };

            Labelbtu[2] = new Label()
            {
                Name = "LabelRefresh",
                Location = new Point(90, 0),
                Size = new Size(38, 38),
                BackColor = ColorPanel.BackColor,
            };

            Labelbtu[3] = new Label()
            {
                Name = "LabelfoldFolder",
                Location = new Point(135, 0),
                Size = new Size(38, 38),
                BackColor = ColorPanel.BackColor,
            };

            panel.BackColor = ColorPanel.BackColor;
            panel.Size = new Size(193, 38);
            panel.Location = new Point(panel.Parent.Width - 193, (panel.Parent.Height - 38) / 2);

            Labelbtu[0].Image = AllImage.FImage_file[0];
            Labelbtu[1].Image = AllImage.FImage_file[2];
            Labelbtu[2].Image = AllImage.FImage_file[4];
            Labelbtu[3].Image = AllImage.FImage_file[6];

            for (int i = 0; i < 4; i++)
            {
                panel.Controls.Add(Labelbtu[i]);
                Labelbtu[i].MouseUp += new MouseEventHandler(Labelbtu_MouseUp);
                Labelbtu[i].MouseEnter += new EventHandler(Labelbtu_MouseEnter);
                Labelbtu[i].MouseLeave += new EventHandler(Labelbtu_MouseLeave);
            }
        }


        private void Labelbtu_MouseUp(object sender, MouseEventArgs e)
        {
            Label label = (Label)sender;
            int i;
            for (i = 0; i < 4; i++)
            {
                if (label.Equals(Labelbtu[i]))
                {
                    if (backcall[i] != null)
                    {
                        backcall[i]();
                    }
                }
            }
        }
        private void Labelbtu_MouseEnter(object sender, EventArgs e)
        {
            Label label = (Label)sender;
            int i;
            for (i = 0; i < 4; i++)
            {
                if (label.Equals(Labelbtu[i]))
                {
                    label.Image = AllImage.FImage_file[i * 2 + 1];
                }
            }
        }
        private void Labelbtu_MouseLeave(object sender, EventArgs e)
        {
            Label label = (Label)sender;
            int i;
            for (i = 0; i < 4; i++)
            {
                if (label.Equals(Labelbtu[i]))
                {
                    label.Image = AllImage.FImage_file[i * 2];
                }
            }
        }
    }
}